package file

import (
	"os"
	"errors"
	"strings"
	"runtime"
)

//获取路径权限
func PathPrivlege(path string) (os.FileMode, error){
	path = FormatPath(path)
	file_info, err := os.Stat(path)
	if err !=nil {
		if os.IsNotExist(err) {
			return 0, err
		}
		return 0, errors.New("os.Stat failed")
	}
	file_mode := file_info.Mode()
	perm := file_mode.Perm()
	return perm,nil
}

//格式化路径
func FormatPath(path string) string{
	if "windows" == runtime.GOOS {
		path = strings.Replace(path, "\\", "\\\\", -1)
	}else{
		path = strings.Replace(path, "\\", "/", -1)
	}
	return path
}